﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AppStore.Domain.Abstract;
using AppStore.Domain.DAO;
using AppStore.Domain.Entities;

namespace AppStore.Domain.Concrete
{
    public class ApplicationRepository : IApplicationRepository
    {
        private AppStoreDBConnection context = new AppStoreDBConnection();

        public IQueryable<Application> Applications { get { return context.Applications; } }

        public void addApplication(Application application)
        {
            context.Applications.Add(application);
            context.SaveChanges();
        }

        public void removeApplication(int applicationId)
        {
            context.Applications.Remove(context.Applications.Single(a => a.applicationId == applicationId));
            context.SaveChanges();
        }

        public void saveEditedChanges(Application application)
        {
            context.Entry(application).State = EntityState.Modified;
            context.SaveChanges();
        }
    }
}
